package com.cctc.rds.nrpc.core.server.connnection;

import com.cctc.rds.nrpc.api.connection.Connection;
import com.cctc.rds.nrpc.api.connection.server.AbstractServerConnectionPool;
import io.netty.channel.Channel;

import java.net.InetSocketAddress;

public class DefaultServerConnectionPool extends AbstractServerConnectionPool {

    public void put(Channel channel) {
        if (channel != null) {
            ServerConnection connection = new ServerConnection(channel);
            super.put(connection);
        }
    }

    public void remove(Channel channel) {
        if (channel != null) {
            InetSocketAddress socketAddress = (InetSocketAddress) channel.remoteAddress();
            String remoteIp = socketAddress.getAddress().getHostAddress();
            int remotePort = socketAddress.getPort();
            super.remove(remoteIp, remotePort);
        }
    }
}
